import javax.media.j3d.BranchGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;


public class Montador {
	
	private Peca[] pecas;
	
	static Peca peca1 = new Peca(new boolean[][][] {
			{{true, true, true, true},
			{true, false, false, false},
			{true, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, true},
			{false, false, false, false},
			{false, true, true, true},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});
	
	static Peca peca2 = new Peca(new boolean[][][] {
			{{false, false, false, true},
			{true, true, true, true},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, true},
			{true, false, false, false},
			{true, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});
	
	static Peca peca3 = new Peca(new boolean[][][] {
			{{true, false, false, true},
			{true, false, false, false},
			{true, false, false, false},
			{false, false, false, false}},
			
			{{true, true, true, true},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});
	
	static Peca peca4 = new Peca(new boolean[][][] {
			{{false, true, true, true},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{true, true, false, false},
			{true, false, false, false},
			{true, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{true, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});

	static Peca peca5 = new Peca(new boolean[][][] {
			{{false, false, false, false},
			{true, true, true, true},
			{true, false, false, true},
			{false, false, false, false}},
			
			{{true, false, false, false},
			{true, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});
	
	static Peca peca6 = new Peca(new boolean[][][] {
			{{false, false, true, true},
			{true, true, true, false},
			{true, false, true, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{true, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});
	
	static Peca peca7 = new Peca(new boolean[][][] {
			{{false, false, true, false},
			{true, false, true, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{true, true, true, false},
			{false, true, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, true, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});
	
	static Peca peca8 = new Peca(new boolean[][][] {
			{{false, false, true, true},
			{false, false, false, true},
			{false, false, true, true},
			{false, false, false, false}},
			
			{{true, true, true, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}},
			
			{{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false},
			{false, false, false, false}}
	});
	
	private static final float TC = 0.1f; 
	
	private static void montarUnidadePeca(BranchGroup group, float x, float y, float z) {
		ColorCube cube = new ColorCube(TC);
		TransformGroup tg = new TransformGroup();
		Transform3D transform = new Transform3D();
		Vector3f vector = new Vector3f(TC*x, TC*y, TC*z);
		transform.setTranslation(vector);
		tg.setTransform(transform);
		tg.addChild(cube);
		group.addChild(tg);
	}
	
	private static void montarPeca(BranchGroup group, Peca peca) {
		float px = 0.0f;
		float py = 0.0f;
		float pz = 0.0f;
		
		for (boolean [][] x: peca.getPeca()) {
			for (boolean [] y: x) {
				for (boolean z : y) {
					if (z) {
						montarUnidadePeca(group, pz, px, py);
					}
					pz++;
				}
				py++;
			}
			px++;
		}
	}
	
	public static void main(String[] args) {
		SimpleUniverse universe = new SimpleUniverse();

		BranchGroup group = new BranchGroup();

		montarPeca(group, peca2);

		universe.getViewingPlatform().setNominalViewingTransform();
		universe.addBranchGraph(group);
	}
}
